package com.example.dzbsh.service;

import java.util.List;
import java.util.Map;

import com.example.dzbsh.dao.AdminMapper;
import com.example.dzbsh.model.Admin;
import com.example.dzbsh.model.AdminExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AdminService {

    @Resource
    AdminMapper ddAdminMapper;

    public boolean add(Admin ppAdmin){
        return ddAdminMapper.insert(ppAdmin)==1;
    }

    public boolean modify(Admin ppAdmin){
        return ddAdminMapper.updateByPrimaryKey(ppAdmin)==1;
    }

    public Boolean delete(String ppAdminID) {
        return ddAdminMapper.deleteByPrimaryKey(ppAdminID) == 1;
    }

    public Admin findOne(String ppAdminID){
        return ddAdminMapper.selectByPrimaryKey(ppAdminID);
    }
    
    public List<Map<String, Object>> findCustomByDeptId(String ppDeptID){
        return ddAdminMapper.findCustomByDeptId(ppDeptID);
    }
    
    public List<Map<String, Object>> findCustomAll(){
        return ddAdminMapper.findCustomAll();
    }

    public List<Admin> findByDeptId(String ppDeptID){
        AdminExample mmExample = new AdminExample();
        AdminExample.Criteria criteria = mmExample.createCriteria();
        criteria.andDeptidEqualTo(ppDeptID);
        return ddAdminMapper.selectByExample(mmExample);
    }
    
    public List<Admin> findByLoginname(String ppLoginName){
    	AdminExample mmExample = new AdminExample();
        AdminExample.Criteria criteria = mmExample.createCriteria();
        criteria.andLoginnameEqualTo(ppLoginName);
        return ddAdminMapper.selectByExample(mmExample);
    }
    
    public List<Admin> findExitByLoginname(String ppLoginname,String ppAdminId) {
    	AdminExample mmExample = new AdminExample();
		mmExample.createCriteria().andLoginnameEqualTo(ppLoginname).andAdminidNotEqualTo(ppAdminId);
		return ddAdminMapper.selectByExample(mmExample);
	}
    
    public List<Map<String, Object>> findByLoginnameAndPassword(String ppLoginName,String ppPassword){
        return ddAdminMapper.findCustomByLoginNameAndPassword(ppLoginName, ppPassword);
    }
}
